package com.szgr.baoyin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.szgr.baoyin.R;
import com.szgr.baoyin.model.ProductColor;
import com.szgr.baoyin.model.ProductType;

import java.util.List;

/**
 * Created by yang on 15/9/30.
 */
public class ColorGridAdapter extends BaseAdapter {
    private Context mContext;
    private List<ProductColor> data;
    public ColorGridAdapter(Context context,List<ProductColor> data){
        mContext = context;
        this.data = data;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_type_and_color_grid_view,parent,false);

        }
        ProductColor type = data.get(position);
        if(type.isSelected()){
            convertView.setBackgroundResource(R.drawable.xuanzeyansexinghao2);
        }else{
            convertView.setBackgroundResource(R.drawable.xuanzeyansexinghao);
        }
        return convertView;
    }

    public class ViewHolder{
        ImageView iv_icon;
        TextView tv_name;
    }
}
